<template>
  <!-- 普通列表布局 -->
  <view style="width: 100%">
    <template v-if="menuList.length > 0">
      <view v-for="(item, index) in menuList" :key="index" class="drop-down-item" @click.stop.passive="subItemClick(item, index)">
        <text class="item-text" :style="{ fontSize: itemFontSize, color: currDefaultValue.includes(item.value) ? activeColor : inactiveColor }">
          {{ item.label }}
        </text>
        <view class="icon-box" :style="{ opacity: currDefaultValue.includes(item.value) ? 1 : 0 }">
          <mxp-icon name="dui" :color="activeColor" :size="itemFontSize"></mxp-icon>
        </view>
      </view>
    </template>
    <template v-else>
      <view style="display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%" :style="{ height: menuHeight }">
        <image src="../../mxp-tool/static/images/global-state/not-data.svg" style="width: 120px; height: 120px" mode="scaleToFill"></image>
        <view>
          <text style="font-size: 14px" :style="{ color: inactiveColor }">暂无可选数据</text>
        </view>
      </view>
    </template>
  </view>
</template>

<script lang="ts" setup>
  import MxpIcon from '@/mxp-ui/mxp-icon/mxp-icon.vue';
  import type { $AllColorStr, $SizeUnitStr } from '@/mxp-ui/mxp-tool/types/interface';
  import { type PropType, computed } from 'vue';

  import type { $TrimDropDownMultipleListLevel1Item } from './type';
  defineOptions({
    name: 'item-type5',
  });

  const props = defineProps({
    /** 每一项的筛选数据 */
    menuList: { type: Object as PropType<$TrimDropDownMultipleListLevel1Item[]>, required: true },
    /** 未选中颜色 */
    inactiveColor: { type: String as PropType<$AllColorStr>, required: true },
    /** 选中颜色颜色 */
    activeColor: { type: String as PropType<$AllColorStr>, required: true },
    /** 筛选列表的高度 */
    menuHeight: { type: String as PropType<$SizeUnitStr>, required: true },
    /** 筛选 列表的每一项 的文字大小 */
    itemFontSize: { type: String as PropType<$SizeUnitStr>, required: true },
    /** 默认选中 */
    defaultValue: { type: [Array, Object] as PropType<Record<number | string, unknown[]> | unknown[] | undefined>, default: undefined },
  });
  const emits = defineEmits<{
    (e: 'click', item: $TrimDropDownMultipleListLevel1Item, menuIndex: number): void;
  }>();

  const currDefaultValue = computed<unknown[]>(() => (props.defaultValue || []) as unknown[]);

  /** 点击事件 */
  function subItemClick(item: $TrimDropDownMultipleListLevel1Item, menuIndex: number) {
    emits('click', item, menuIndex);
  }
</script>

<style scoped lang="scss">
  .drop-down-item {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: 10px 15px;
    font-size: 14px;
    color: #333333;

    .item-text {
      flex: 1;
      transition: color 0.3s;
    }

    .icon-box {
      margin-left: 8px;
      transition: opacity 0.3s;
    }
  }
</style>
